package com.xjscrm.console.service.customer.operatePlan.impl;

import com.xjscrm.common.constant.ResponseMsg;
import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.common.result.ResponseCode;
import com.xjscrm.console.param.operatePlan.BatchAddGroupPullPlanDeviceDto;
import com.xjscrm.console.param.operatePlan.BatchSetAddFanGroupDto;
import com.xjscrm.console.param.operatePlan.SetAddFanGroupDto;
import com.xjscrm.console.service.customer.operatePlan.GroupPullBatchService;
import com.xjscrm.console.service.customer.operatePlan.GroupPullService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GroupPullBatchServiceImpl implements GroupPullBatchService {

    @Autowired
    private GroupPullService groupPullService;
    @Override
    public void batchAddPlanDevice(BatchAddGroupPullPlanDeviceDto batchAddGroupPullPlanDeviceDto) {
        if(batchAddGroupPullPlanDeviceDto.getDeviceUniqueIds()==null||batchAddGroupPullPlanDeviceDto.getDeviceUniqueIds().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        if(batchAddGroupPullPlanDeviceDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        for (Long deviceUniqueId:batchAddGroupPullPlanDeviceDto.getDeviceUniqueIds()) {
          try {
              batchAddGroupPullPlanDeviceDto.setDeviceUniqueId(deviceUniqueId);
              groupPullService.addPlanDevice(batchAddGroupPullPlanDeviceDto);
          }catch (Exception e){
              e.printStackTrace();
          }
        }
    }

    @Override
    public void batchDelPlanDevice(BatchAddGroupPullPlanDeviceDto batchAddGroupPullPlanDeviceDto) {
        if(batchAddGroupPullPlanDeviceDto.getIds()==null||batchAddGroupPullPlanDeviceDto.getIds().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        if(batchAddGroupPullPlanDeviceDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }

        for (Long id:batchAddGroupPullPlanDeviceDto.getIds()) {
            try {
                batchAddGroupPullPlanDeviceDto.setId(id);
                groupPullService.delPlanDevice(batchAddGroupPullPlanDeviceDto);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    @Override
    public void batchUpdatePlanDevice(BatchAddGroupPullPlanDeviceDto batchAddGroupPullPlanDeviceDto) {
        if(batchAddGroupPullPlanDeviceDto.getIds()==null||batchAddGroupPullPlanDeviceDto.getIds().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        if(batchAddGroupPullPlanDeviceDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if(batchAddGroupPullPlanDeviceDto.getSleepRule()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        for (Long id:batchAddGroupPullPlanDeviceDto.getIds()) {
            try {
                batchAddGroupPullPlanDeviceDto.setId(id);
                groupPullService.updatePlanDevice(batchAddGroupPullPlanDeviceDto);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

}
